# coding=utf-8
"""
Time:2024/11/7 17:02
"""
'''
此模块是用来生成测试报告和发送邮件的
'''
import sys
sys.path.append('..')
import time
import unittest
from library.HTMLTestRunnerNew import HTMLTestRunner
from library.mail import SendMail
from utiles.handle_path import *

now = time.strftime("%Y-%m-%d-%H-%M-%S")
filename = report_path +"\\"+ str(now) + "_api_report.html"

def auto_run():
    discover = unittest.defaultTestLoader.discover(start_dir=testcase_path,pattern="test_*.py")
    f = open(filename,"wb")
    runner = HTMLTestRunner(stream=f,
                            title="cms接口自动化测试报告",
                            description="用例执行情况如下",
                            tester="小胡")
    runner.run(discover)
    f.close()

def sendMail():
    sm = SendMail(send_msg=filename,attachment=filename)
    sm.send_mail()

if __name__ == '__main__':
    auto_run()
    sendMail()